package com.itheima.test;

import cn.hutool.core.util.RandomUtil;
import com.itheima.domain.db.UserInfo;
import com.itheima.domain.mongo.Sound;

import com.itheima.service.db.UserInfoService;
import com.itheima.service.mongo.SoundService;
import org.apache.dubbo.config.annotation.Reference;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.springframework.boot.test.context.SpringBootTest;
import org.springframework.test.context.junit4.SpringRunner;

@SpringBootTest
@RunWith(SpringRunner.class)
public class SoundDataImport {
    @Reference
    UserInfoService userInfoService;
    @Reference
    SoundService soundService;


    @Test
    public void test0() {
        for (int i = 0; i < 20; i++) {
            long userId = (long)RandomUtil.randomInt(1, 110);

            try {
                //获取userInfo
                UserInfo userInfo = userInfoService.findById(userId);
                Integer age = userInfo.getAge();
                String gender = userInfo.getGender();


                Sound sound = new Sound();
                sound.setCreated(System.currentTimeMillis());
                sound.setUserId(userId);
                sound.setAge(age);
                sound.setGender(gender);
                sound.setSoundUrl("http://192.168.136.160:8888/group1/M00/00/00/wKiIoGDu5M6Ae3A9AAAdt-yUTlw007.m4a");
                soundService.save(sound);
            } catch (Exception e) {

            }
        }
    }
}
